/**
 * 
 */
package com.social.itba.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.collections.MapUtils;

import com.social.itba.model.Director;
import com.social.itba.model.Movie;

/**
 * Service that performs opertions over the movie director. 
 * 
 * @author waabox( emiliano[dot]arango[at]globat[dot]com )
 *
 */
public class DirectorService {
  /**
   * Single instance. 
   */
  private static final DirectorService instance = new DirectorService();
  /**
   * Map of directors.
   */
  private Map<Integer, Director> directors;
  /**
   * default constructor.
   */
  @SuppressWarnings("unchecked")
  private DirectorService() {
    directors = MapUtils.synchronizedMap(new HashMap<Integer, Director>());
  }
  /**
   * @param id {@link Integer} director to search.
   * @return {@link Movie}
   */
  public static Director get(final Integer id) {
    return instance.directors.get(id);
  }
  /**
   * @param id {@link Integer} of the director to delete.
   */
  public static void remove(final Integer id) {
    instance.directors.remove(id);
  }
  /**
   * @param movie {@link Movie} director to add.
   */
  public static void add(final Director director) {
    instance.directors.put(director.getId(), director);
  }
  /**
   * Retrieve all directors.
   * Bad Practice!
   * return {@link List} of {@link Movie}.
   */
  public static List<Director> getAll() {
    List<Director> out = new ArrayList<Director>();
    Set<Integer> set = instance.directors.keySet();
    for (Integer id : set) {
      out.add(instance.directors.get(id));
    }
    return out;
  }
}
